home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / DefDTIcon / IDPort.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-11  |  1KB  |  69 lines

  1. Function ChecKIDPortOrSetUp(VAR IDPort : pMsgPort; portname : STRPTR):Boolean;
  2.  
  3. VAR
  4.     Port, ReplyPort : pMsgPort;
  5.     Message, ms : pMessage;
  6.     return : boolean;
  7.  
  8. Begin
  9.     return := false;
  10.     Forbid;
  11.     { Check that were not allready running }
  12.     Port := FindPort(portname); 
  13.     Permit;
  14.     
  15.     If Port <> NIL then begin
  16.         { already running so tell other copy to quit and exit ourselfs}
  17.         Return := False;
  18.         message := AllocMem(sizeof(tMessage),MEMF_CLEAR);
  19.         if message <> NIL then begin
  20.             ReplyPort := CreateMsgPort;
  21.             if replyport <> NIL then begin
  22.                 message^.mn_Node.ln_Type := NT_MESSAGE;
  23.                 message^.mn_ReplyPort := ReplyPort;
  24.                 message^.mn_Length := sizeof(tMessage);
  25.  
  26.                 PutMsg(Port, Message);
  27.                 ms := WaitPort(ReplyPort);
  28.                 ms := GetMsg(ReplyPort);
  29.                 FreeMem_(message, sizeof(tMessage));
  30.             end;
  31.         end;
  32.     end else begin
  33.         Return := true;
  34.         { create ID port }
  35.         IDPort := CreateMsgPort;
  36.         If IDPort <> NIL then begin
  37.             IDPort^.mp_Node.ln_Name := portname;
  38.             IDPort^.mp_Node.ln_Pri := 0;
  39.             AddPort(IDPort);
  40.         end;
  41.     end;
  42.     CheckIdPortOrSetup := return;
  43. end;
  44.             
  45. Procedure CleanIDPort(IDPort : pMsgPort);
  46.  
  47. VAR
  48.     mes : pMessage;
  49. Begin
  50.     if IDPort <> NIL then begin
  51.         mes := GetMsg(IDPort);
  52.         While mes <> NIL do begin
  53.             ReplyMsg(mes);
  54.             mes := GetMsg(IDPort);
  55.         end;
  56.         RemPort(IDPort);
  57.         DeleteMsgPort(IDPort);
  58.     end;
  59. end;                
  60.             
  61.              
  62.              
  63.              
  64.              
  65.              
  66.              
  67.              
  68.              
  69.